package com.choudou5.solr.util.bean;

import com.choudou5.solr.util.CollUtil;
import com.choudou5.solr.util.DateUtil;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @name：DateRange 说明
 * @author：xuhaowen
 * @date：2018-08-25
 */
public class DateRange implements Serializable {

    private String format;
    private String sqlFormat;
    private List<Date> dateList;
    private long diffMs; //相差毫秒
    private String diffDateType; //相差时间类型 HOUR、DAY、MONTH、YEAR

    public String getFormat() {
        return format;
    }

    public void setFormat(String format) {
        this.format = format;
    }

    public String getSqlFormat() {
        return sqlFormat;
    }

    public void setSqlFormat(String sqlFormat) {
        this.sqlFormat = sqlFormat;
    }

    public List<Date> getDateList() {
        return dateList;
    }

    public void addDate(Date date) {
        if(this.dateList == null){
            this.dateList = new ArrayList<>();
        }
        this.dateList.add(date);
    }

    public void setDateList(List<Date> dateList) {
        this.dateList = dateList;
    }

    public Date getStartDate() {
        return dateList.get(0);
    }

    public String getStartDateStr() {
        return DateUtil.formatDateTime(dateList.get(0));
    }

    public Date getEndDate() {
        return dateList.get(dateList.size() - 1);
    }

    public List<String> toDateStrList(boolean format) {
        List<String> dateList = new ArrayList<>();
        if(format){
            for (Date date : getDateList()) {
                dateList.add(DateUtil.format(date, getFormat()));
            }
        }
        return dateList;
    }

    public List<String> toSolrDateStrList(boolean format) {
        List<String> dateList = new ArrayList<>();
        if(format){
            for (Date date : getDateList()) {
                dateList.add(DateUtil.format(date, getFormat()));
            }
        }
        return dateList;
    }


    public long getDiffMs() {
        return diffMs;
    }

    public void setDiffMs(long diffMs) {
        this.diffMs = diffMs;
    }

    public String getDiffDateType() {
        return diffDateType;
    }

    public void setDiffDateType(String diffDateType) {
        this.diffDateType = diffDateType;
    }
}
